<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="username" lay-verify="title" placeholder="username" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 180px;">
                <select name="select_state" lay-verify="" >
                    <option value="">Select State</option>
                    <option value="PENDING">PENDING</option>
                    <option value="CLEARED">CLEARED</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="tran_token" lay-verify="title" placeholder="Tran Token" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="datetime" id="datetime" placeholder="start_time _ end_time" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="ON|OFF" lay-filter="change_status" {{ d.status != 1 ? 'checked' : '' }}>
</script>
<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var laydate = layui.laydate;

        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        layui.table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('cardRepair')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: 'username', align: 'center', title: 'Username',width:200},
                { field: 'tran_token', align: 'center', title: 'TranToken',
                    templet:function (d) {
                        return '<a target="_blank" href="{:url(\'cardPay\')}?tran_token=' + d.tran_token + '" style="color: #428bca;font-weight:bold;">' + d.tran_token + '</a>';
                    },
                },
                { field: 'card_num', title: 'Card Num',width: 250,
                    templet:function (d) {
                        var num = d.card_num;
                        var num4 = num.substr(-4);
                        return "**** " + num4;
                    },align:"left",totalRowText:'The Total：'},
                {field: 'amount', title: 'RepairAmount($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150, totalRow: true
                },
                {field: 'tran_amount', title: 'TranAmount($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150},
                {field: 'real_amount', title: 'RealAmount($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150},
                {field: 'state', title: 'State', align:"right",
                    style:'font-weight:bold' , width:150},
                { field: 'ctime', align: 'center', title: 'create time',width:200,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'option', title: 'Action', templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs SearchDetail" data-id="' + d.id + '">CurrentType</a>';
                    }, align: 'center', width: 150
                },
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
        });
        layui.form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //余额编辑
        $(document).on('click', '.SearchDetail', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('showRepair')}?id="+id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Log Detail',
                        area: ['1000px', '600px'], //宽高
                        content: e.datas,
                        btn:['Close']
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
    });
</script>